package com.hex.ds.hdrs.app.controller;


import com.hex.bigdata.hbda.annotation.Log;
import com.hex.bigdata.hbda.base.Page;
import com.hex.ds.hdrs.app.po.GroupConf;
import com.hex.ds.hdrs.app.service.impl.GroupConfService;
import com.hex.ds.hdrs.common.page.PageData;
import com.hex.ds.hdrs.engine.service.DispatcherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 分发器应用组 前端控制器
 * </p>
 *
 * @author jie.liu
 * @since 2020-11-26
 */
@Slf4j
@RestController
@Api(tags = "应用组信息")
@RequestMapping("/api/appGroup")
public class GroupConfController {

    @Autowired
    private GroupConfService groupConfService;

    @Autowired
    private DispatcherService dispatcherService;

    /**
     * 应用组分页查询
     *
     * @param groupConf
     * @param page
     * @return
     */
    @GetMapping("/selectPages")
    @ApiOperation("应用分组查询")
    @Log("应用组查询")
    public ResponseEntity<Object> selectPages(GroupConf groupConf, Page page) {
        log.info("【AppGroupController的selectPages参数page】：{}", page.toString());
        PageData data = new PageData(groupConfService.selectPages(groupConf, page), page);
        return new ResponseEntity(data, HttpStatus.OK);

    }

    /**
     * 新增分组
     *
     * @param groupConf
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增分组")
    @Log("应用组新增")
    public ResponseEntity<Object> add(@RequestBody GroupConf groupConf) {
        log.info("【AppGroupController.add】参数GroupConf: {}", groupConf.toString());
        this.groupConfService.add(groupConf);
        return new ResponseEntity("新增成功", HttpStatus.OK);
    }

    /**
     * 应用组删除
     *
     * @param pkIds
     * @return
     */
    @PostMapping("/del")
    @ApiOperation("应用组删除")
    @Log("应用组删除")
    public ResponseEntity<Object> del(@RequestBody List<String> pkIds) {
        log.info("【AppGroupController.del】参数GroupConf: {}", pkIds.toString());
        this.groupConfService.del(pkIds);
        return new ResponseEntity("删除成功", HttpStatus.OK);
    }

    /**
     * 应用组修改
     *
     * @param groupConf
     * @return
     */
    @PostMapping("/edit")
    @ApiOperation("应用组修改")
    @Log("应用组修改")
    public ResponseEntity<Object> edit(@RequestBody GroupConf groupConf) {
        log.info("【AppGroupConfController的edit】参数GroupConf: {}", groupConf.toString());
        this.groupConfService.edit(groupConf);
        return new ResponseEntity("修改成功", HttpStatus.OK);
    }

    /**
     * 查询字段是否重复
     *
     * @param groupConf
     * @return
     */
    @PostMapping("/checkAppGroupData")
    @ApiOperation("判断是否重复")
    public ResponseEntity<Object> checkAppGroupData(@RequestBody GroupConf groupConf) {
        log.info("【AppGroupConfController的checkAppGroupData】: {}", groupConf.toString());
        boolean result = this.groupConfService.checkAppGroupData(groupConf);
        return new ResponseEntity(result, HttpStatus.OK);
    }

    /**
     * 应用组编码查询
     *
     * @return
     */
    @ApiOperation("应用组编码查询")
    @GetMapping("/qryGroupCode")
    public ResponseEntity<Object> qryGroupCode() {
        log.debug("【进入AppConfController的qryGroupCode】");
        List<GroupConf> list = this.groupConfService.qryGroupCode();
        return new ResponseEntity(list, HttpStatus.OK);
    }

    @ApiOperation("刷新线程组")
    @PostMapping("/refreshGroup")
    @Log("应用组刷新线程")
    public ResponseEntity<Object> refreshGroup(@RequestBody GroupConf groupConf) {
        log.debug("【进入AppConfController的refreshGroup】");
        return new ResponseEntity(this.dispatcherService.refreshGroup(groupConf), HttpStatus.OK);
    }
}

